import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kkhousekeep/widget/shadow_widget.dart';

import '../config/enum.dart';
import '../models/house_authentication_list_entity.dart';

class HouseNotificationItem extends StatefulWidget {
  HouseNotificationItem(this._houseNotification, this.onTap)
      : super(key: ValueKey(_houseNotification.id));
  final HouseAuthenticationListObjList _houseNotification;
  final GestureTapCallback? onTap;

  @override
  State<StatefulWidget> createState() {
    return _HouseNotificationItemState();
  }
}

class _HouseNotificationItemState extends State<HouseNotificationItem> {
  @override
  Widget build(BuildContext context) {
    CheckStatus? status = checkStatus(widget._houseNotification.checkStatus);
    String statusBgAssertImage = "";
    Color? statusTextColor;
    if (status == CheckStatus.unchecked) {
      statusBgAssertImage = 'assets/images/flag_notification_pending.png';
      statusTextColor = const Color(0xFFDD5045);
    } else if (status == CheckStatus.fail) {
      statusBgAssertImage = 'assets/images/flag_notification_fail.png';
      statusTextColor = const Color(0xFF636363);
    } else if (status == CheckStatus.passed) {
      statusBgAssertImage = 'assets/images/flag_notification_passed.png';
      statusTextColor = const Color(0xFF55D4A5);
    }

    return GestureDetector(
      onTap: widget.onTap,
      child: ShadowWidget.fixedHeight(
        backgroundColor: Colors.white,
        marginHorizontal: 32,
        marginVertical: 8,
        child: Container(
          height: 192.h,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(16.w), color: Colors.white),
          child: Stack(
            alignment: Alignment.center,
            children: [
              Positioned(
                top: 0,
                right: 0,
                height: 56.h,
                child: Container(
                  width: 180.w,
                  alignment: Alignment.centerRight,
                  padding: EdgeInsets.only(right: 32.w),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage(statusBgAssertImage),
                          fit: BoxFit.fill)),
                  child: Text(
                    status?.description ?? "",
                    style: TextStyle(color: statusTextColor, fontSize: 28.sp),
                  ),
                ),
              ),
              Positioned(
                left: 36.w,
                top: 32.h,
                child: Text(widget._houseNotification.updateTime,
                    style: TextStyle(
                        fontSize: 28.sp, color: const Color(0xFF7C7E80))),
              ),
              Positioned(
                left: 36.w,
                child: Text(
                  (widget._houseNotification.roomName),
                  style: TextStyle(
                    fontSize: 32.sp,
                    color: const Color(0xFF333333),
                  ),
                ),
              ),
              Positioned(
                left: 36.w,
                bottom: 32.h,
                child: Text(
                  '申请时间 ${widget._houseNotification.createTime}',
                  style: TextStyle(
                    fontSize: 24.sp,
                    color: const Color(0xFF7C7E80),
                  ),
                ),
              ),
              Positioned(
                right: 20.w,
                child: Image(
                  image: const AssetImage(
                      'assets/images/icon_segue_arrow_grey.png'),
                  width: 48.w,
                  height: 48.h,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  CheckStatus? checkStatus(int status) {
    CheckStatus? checkStatus;
    CheckStatus.values.asMap().forEach((key, value) {
      if (value.value == status) {
        checkStatus = value;
      }
    });
    return checkStatus;
  }
}
